import { Image, StyleSheet, AppState } from 'react-native'
import React, { Component, useState, useEffect } from 'react'
import 'react-native-get-random-values';
import { store } from "./redux/store"
import { syncPageGetFriendMsg, asyncGetFriendList, syncPageGetFriendMsgSeq, syncPageGetGroupMsgSeq, asyncGetGroupList } from "./redux/features/appSlice"
import { Provider, connect } from 'react-redux'
import { RootSiblingParent } from 'react-native-root-siblings';
import { NavigationContainer, useIsFocused } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createStackNavigator, TransitionPresets, } from '@react-navigation/stack';
import { Provider as AntDesignProvider } from '@ant-design/react-native'
import { ConfigProvider } from '@pingtou/rn-vant'
import { pTx } from "./utils/dimensions"
import { RealmProvider } from '@realm/react';
import { useRealm, useQuery } from '@realm/react'
import { schemaName } from "./realm"
import { Profile } from "./realm"
import Realm from "realm"


import { formatFriendMsg, formatGroupMsg } from "./utils/formatFriendMsg"
import { fetch, addEventListener } from "@react-native-community/netinfo";
import useWebsocket from './api/websocket'
import loadFromLocalStorages from "./loadFromLocalStorages"


import CreateWallet from "./views/createWallet"
import Community from "./views/community"
import Wallet from "./views/wallet"
import ImportWalletMethod from "./views/wallet/importWalletMethod"
import ImportPrivateKey from "./views/wallet/importPrivateKey"
import ImportMnemonic from "./views/wallet/importMnemonic"
import WalletDetails from "./views/wallet/walletDetails"
import CustomNetwork from "./views/wallet/customNetwork"
import WalletNetworkList from "./views/wallet/walletNetworkList"
import CollectionCode from "./views/wallet/collectionCode"
import Transfer from "./views/wallet/transfer"
import ExportPrivateKey from "./views/wallet/exportPrivateKey"
import CreateWalletMnemonic from "./views/wallet/createWalletMnemonic"

import Mine from "./views/mine"
import MineDetailsList from "./views/mine/mineDetailsList"
import MineSettings from "./views/mine/settings"
import MineSwitchAccount from "./views/mine/switchAccount"
import SetAdd from "./views/mine/setAdd"




import Chat from "./views/chat"
import AddFriends from "./views/chat/addFriends"
import ApplyForFriend from "./views/chat/applyForFriend"
import AddFriendList from "./views/chat/addFriendList"
import AddressBook from "./views/chat/addressBook"
import FriendMsg from "./views/chat/friendMsg"
import RedPacketInfo from "./views/chat/redPacketInfo"
import FriendTransferInApp from "./views/chat/friendTransferInApp"
import FriendInfo from "./views/chat/friendInfo"
import FriendInfoMaterial from "./views/chat/friendInfoMaterial"
import CreateGroupChat from "./views/chat/createGroupChat"
import GroupList from "./views/chat/groupList"
import GroupMsg from "./views/chat/groupMsg"
import GroupInfoMaterial from "./views/chat/groupInfoMaterial"
import SetGroupJoin from "./views/chat/setGroupJoin"
import GroupManage from "./views/chat/groupManage"
import SendGroupJoin from "./views/chat/sendGroupJoin"
import GroupAdmins from "./views/chat/groupAdmins"
import GroupMembers from "./views/chat/groupJoinReply"
import GroupInfoName from "./views/chat/groupName"



import FullVideo from "./views/fullVideo"
import NotOpen from "./views/notOpen"



import Dapp from "./views/dapp"
import Search from "./views/dapp/search"
import Web3View from "./views/dapp/web3View"
import MyDapp from "./views/dapp/myDapp"

import LogIn from "./views/logIn"





const Tab = createBottomTabNavigator();
const Stack = createStackNavigator();

function MainPage(props) {
    const isFocused = useIsFocused();
    const realm = useRealm();
    const userInfo = useQuery(schemaName.UserInfo, userInfo => {
        return userInfo.filtered('Current = true');
    })[0];
    const { app } = store.getState()
    const [isLocalPage, setIsLocalPage] = useState(true)
    const { wsData, readyState, closeWebSocket, reconnect, ws } = useWebsocket()

    useEffect(() => {
        if (Object.keys(wsData).length !== 0) {
            console.log(wsData, "-----------------wsData")
            if (wsData.S) {
                if (!wsData.G) {
                    let MsgLis = realm.objects(schemaName.FriendMsgLis)
                    realm.write(() => {
                        let filtered = MsgLis.filtered(`S == ${wsData.S}`)
                        if (filtered.length == 0) {
                            switch (wsData.MT) {
                                case 14:
                                    //好友红包领取
                                    const filteredRedPacket = MsgLis.filtered(`RedPacketId == ${Number(wsData.M)}`)
                                    console.log(filteredRedPacket)
                                    if (filteredRedPacket.length > 0) {
                                        console.log("11122")
                                        realm.create(schemaName.FriendMsgLis, { ...filteredRedPacket[0], RedPacketIdState: 1 }, true);
                                    }
                                    realm.create(schemaName.FriendMsgLis, { ...wsData, _id: new Realm.BSON.UUID(), UserId: userInfo.Id }, true);
                                    break;
                                case 42:
                                    //好友通过需要重新加载好友列表再创建聊天
                                    store.dispatch(async (dispatch) => {
                                        await asyncGetFriendList(userInfo.Id)(dispatch)
                                    }).then(res => {
                                        realm.write(() => {
                                            realm.create(schemaName.FriendMsgLis, { ...wsData, _id: new Realm.BSON.UUID(), UserId: userInfo.Id }, true);
                                        })
                                        store.dispatch((dispatch) => {
                                            dispatch({ type: 'app/SetFriendMsg', payload: formatFriendMsg() })
                                        })
                                    })
                                    break;
                                case 43:
                                    //好友删除需要给好友进行标记是否已被删除
                                    let FriendListItem = realm.objects(schemaName.FriendList).filtered(`UserId == ${userInfo.Id} and F == ${wsData.F}`)[0]
                                    if (FriendListItem) {
                                        realm.create(schemaName.FriendList, { ...FriendListItem, State: 0 }, true);
                                        store.dispatch(async (dispatch) => {
                                            await asyncGetFriendList(userInfo.Id)(dispatch)
                                        }).then(res => {
                                            store.dispatch((dispatch) => {
                                                dispatch({ type: 'app/SetFriendMsg', payload: formatFriendMsg() })
                                            })
                                        })
                                    }
                                    break;
                                case 45:
                                    break;
                                default:
                                    realm.create(schemaName.FriendMsgLis, { ...wsData, _id: new Realm.BSON.UUID(), UserId: userInfo.Id }, true);
                                    break;
                            }
                        }

                        realm.create(schemaName.FriendMsgSeq, { Cur: wsData.S, Total: wsData.S, UserId: userInfo.Id }, true);
                    })
                    if (wsData.F == app.cuurentPersonalFriendPageInfo.F) {
                        store.dispatch((dispatch) => {
                            syncPageGetFriendMsg(wsData)(dispatch)
                            //已读
                            // syncPageGetFriendMsgSeq(wsData.F, userInfo.Id)(dispatch)
                        })
                    } else {
                        // 未读
                        store.dispatch((dispatch) => {
                            dispatch({ type: 'app/SetFriendMsg', payload: formatFriendMsg() })
                        })
                    }

                } else {
                    realm.write(() => {
                        const GroupFilteredItem = realm.objects(schemaName.GroupMsgLis).filtered(`S == ${wsData.S} and G == ${wsData.G}`)
                        if (GroupFilteredItem.length > 0) return
                        if (wsData.F == userInfo.Id && [0, 2, 3, 4, 5, 65].indexOf(wsData.MT) !== -1) return //群自己发
                        switch (wsData.MT) {
                            case 99:

                                break;
                            case 60:
                                //好友通过需要重新加载群列表再创建聊天
                                store.dispatch(async (dispatch) => {
                                    await asyncGetGroupList(userInfo.Id)(dispatch)
                                }).then(res => {
                                    realm.write(() => {
                                        realm.create(schemaName.GroupMsgLis, { ...wsData, _id: new Realm.BSON.UUID(), UserId: userInfo.Id }, true);
                                    })
                                    store.dispatch((dispatch) => {
                                        dispatch({ type: 'app/SetGroupMsg', payload: formatGroupMsg() })
                                    })
                                })
                                break;

                            default:
                                realm.create(schemaName.GroupMsgLis, { ...wsData, _id: new Realm.BSON.UUID(), UserId: userInfo.Id }, true);
                                break;
                        }
                        if (wsData.G == app.cuurentPersonalFriendPageInfo.G) {
                            store.dispatch((dispatch) => {
                                syncPageGetFriendMsg(wsData)(dispatch)
                                // //已读
                                // syncPageGetGroupMsgSeq(wsData.G, userInfo.Id)(dispatch)
                            })
                        } else {
                            // 未读
                            store.dispatch((dispatch) => {
                                dispatch({ type: 'app/SetGroupMsg', payload: formatGroupMsg() })
                            })
                        }
                    })
                    realm.write(() => {
                        realm.create(schemaName.GroupMsgSeq, { G: wsData.G, Cur: wsData.S, Total: wsData.S, UserId: userInfo.Id }, true);
                    })
                }

            }

        }
        if (readyState.key === 3 && isLocalPage) {
            reconnect()
        }
    }, [wsData, readyState, isLocalPage])


    const [timerId, setTimerId] = useState(null);
    useEffect(() => {
        const id = setInterval(() => {
            if (app.isLogin || readyState.key == 1) return
            ws.current?.send('1')
        }, 15000);
        setTimerId(id);
        return () => {
            clearInterval(timerId); // 组件卸载时清除定时器
        };
    }, [readyState]);
    useEffect(() => {
        if (app.isLogin) {
            console.log(app.isLogin)
            setTimeout(() => {
                props.navigation.navigate('logIn')
            })
        }
    }, [app.isLogin, isFocused])

    return (
        <Tab.Navigator
            screenOptions={({ route }) => ({
                tabBarIcon: ({ focused, color, size }) => {
                    let iconName;
                    if (route.name === 'chat') {
                        iconName = !focused
                            ? require('./assets/image/chat.png')
                            : require('./assets/image/chat-active.png');
                    } else if (route.name === 'community') {
                        iconName = !focused
                            ? require('./assets/image/community.png')
                            : require('./assets/image/community-active.png');
                    } else if (route.name === 'wallet') {
                        iconName = !focused
                            ? require('./assets/image/wallet.png')
                            : require('./assets/image/wallet-active.png');
                    } else if (route.name === 'dapp') {
                        iconName = !focused
                            ? require('./assets/image/browser.png')
                            : require('./assets/image/browser-active.png');
                    } else if (route.name === 'mine') {
                        iconName = !focused
                            ? require('./assets/image/mine.png')
                            : require('./assets/image/mine-active.png');
                    }
                    return <Image style={styles.navigatorImage} source={iconName}></Image>;
                },
                tabBarActiveTintColor: '#0A0C14',
                tabBarInactiveTintColor: '#A9ACB6',
                tabBarLabelStyle: { fontWeight: 500 },
                tabBarItemStyle: { width: 100 },
                tabBarStyle: {
                    paddingBottom: pTx(5),
                },
            })}
            initialRouteName="chat">
            <Tab.Screen name="chat" component={Chat} options={{
                tabBarLabel: "聊天",
                headerShown: false,
            }} />
            <Tab.Screen name="community" component={Community} options={{
                headerShown: false,
                tabBarLabel: "社区",
            }} />
            <Tab.Screen name="wallet" component={Wallet} options={{
                title: "",
                tabBarLabel: "钱包"
            }} />
            <Tab.Screen name="dapp" component={Dapp} options={{
                headerShown: false,
                tabBarLabel: "Dapp",
            }} />
            <Tab.Screen name="mine" component={Mine} options={{
                headerShown: false,
                tabBarLabel: "我的",
            }} />

        </Tab.Navigator>
    )
}
const mapState = state => state.wallet;


function Pages({ isWallet }) {
    const [networkState, setNetworkState] = useState('online');
    const [appState, setAppState] = useState(AppState.currentState);
    const { loadInitialData } = loadFromLocalStorages()
    useEffect(() => {
        loadInitialData()
    }, [])

    useEffect(() => {
        const unsubscribe = addEventListener((state) => {
            setNetworkState(state.isConnected ? 'online' : 'offline');
        });

        return () => unsubscribe();
    }, []);

    useEffect(() => {
        if (networkState === 'offline') {
            // 尝试重连逻辑
            fetch().then(state => {
                // console.log("Connection type", state.type);
                // console.log("Is connected?", state.isConnected);
                // console.log('网络已断开，尝试重连111111111111111111');
                // asyncLoadFromLocalStorages()

            });
            // 这里可以添加重连代码，比如发起网络请求等
        } else {
            fetch().then(state => {
                // asyncLoadFromLocalStorages()
            })
        }
    }, [networkState])


    // 组件挂载后注册监听器
    // useEffect(() => {
    //     AppState.addEventListener('change', handleAppStateChange);
    //     return () => {
    //         // 组件卸载时移除监听器
    //         AppState.removeEventListener('change', handleAppStateChange);
    //     };
    // }, []);

    // const handleAppStateChange = (nextAppState) => {
    //     if (appState.match(/active|background/) && nextAppState === 'active') {
    //         // console.log('应用从锁屏状态变为开屏状态');
    //         // asyncLoadFromLocalStorages()
    //     } else if (appState === 'active' && nextAppState.match(/inactive|background/)) {
    //         // console.log('应用从开屏状态变为锁屏状态');
    //         // 这里可以执行锁屏前的请求操作
    //     }

    //     setAppState(nextAppState);
    // };

    return (
        <>
            {isWallet ?
                (
                    <NavigationContainer>
                        <RootSiblingParent>
                            <ConfigProvider>
                                <AntDesignProvider>
                                    <Stack.Navigator screenOptions={{
                                        gestureEnabled: true,
                                        cardOverlayEnabled: true,
                                        ...TransitionPresets.SlideFromRightIOS,
                                        cardStyle: {
                                            backgroundColor: "#EDEDED",
                                        },
                                        headerTitleStyle: {
                                            fontSize: 18,
                                        },
                                    }}>

                                        <Stack.Screen
                                            name="MainPage"
                                            component={MainPage}
                                            options={{ headerShown: false }}
                                        />
                                        <Stack.Screen name="web3View" component={Web3View}
                                            options={{
                                                title: "",
                                                headerTitleAlign: 'center',
                                            }}
                                        />
                                        <Stack.Screen name="myDapp" component={MyDapp}
                                            options={{
                                                title: "我的Dapps",
                                                headerTitleAlign: 'center',
                                            }}
                                        />
                                        <Stack.Screen name="search" component={Search}
                                            options={{
                                                title: "",
                                                headerTitleAlign: 'center',
                                                headerShown: false
                                            }}
                                        />
                                        <Stack.Screen name="importWalletMethod" component={ImportWalletMethod}
                                            options={{
                                                title: "导入方式",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#f3f4f5',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="importPrivateKey" component={ImportPrivateKey}
                                            options={{
                                                title: "私钥导入",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#f3f4f5',
                                                },
                                                cardStyle: {
                                                    backgroundColor: "#fff",
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="importMnemonic" component={ImportMnemonic}
                                            options={{
                                                title: "助记词导入",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#f3f4f5',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="walletDetails" component={WalletDetails}
                                            options={{
                                                title: "钱包详情",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#f3f4f5',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="customNetwork" component={CustomNetwork}
                                            options={{
                                                title: "币安智能链",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="walletNetworkList" component={WalletNetworkList}
                                            options={{
                                                title: "钱包列表",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                headerShadowVisible: false,
                                                ...TransitionPresets.ModalPresentationIOS,
                                            }}
                                        />
                                        <Stack.Screen name="collectionCode" component={CollectionCode}
                                            options={{
                                                title: "收款",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: 'rgba(51, 225, 144, 1)',
                                                },
                                                headerShadowVisible: false,
                                            }}
                                        />
                                        <Stack.Screen name="transfer" component={Transfer}
                                            options={{
                                                title: "转账",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                cardStyle: {
                                                    backgroundColor: "#fff",
                                                },
                                                headerShadowVisible: false,
                                            }}
                                        />
                                        <Stack.Screen name="exportPrivateKey" component={ExportPrivateKey}
                                            options={{
                                                title: "导出私钥",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                cardStyle: {
                                                    backgroundColor: "#EDEDED",
                                                },
                                                headerShadowVisible: false,
                                                ...TransitionPresets.ModalPresentationIOS,
                                            }}
                                        />
                                        <Stack.Screen name="createWalletMnemonic" component={CreateWalletMnemonic}
                                            options={{
                                                title: "创建钱包",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                cardStyle: {
                                                    backgroundColor: "#EDEDED",
                                                },
                                                headerShadowVisible: false,
                                            }}
                                        />




                                        <Stack.Screen name="addFriends" component={AddFriends}
                                            options={{
                                                title: "添加朋友",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="applyForFriend" component={ApplyForFriend}
                                            options={{
                                                title: "申请添加好友",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="addFriendList" component={AddFriendList}
                                            options={{
                                                title: "新的朋友",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="addressBook" component={AddressBook}
                                            options={{
                                                title: "通讯录",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="friendMsg" component={FriendMsg}
                                            options={{
                                                title: "",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="redPacketInfo" component={RedPacketInfo}
                                            options={{
                                                title: "",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#F35E4D',
                                                },
                                                cardStyle: {
                                                    backgroundColor: "#ffffff",
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="friendTransferInApp" component={FriendTransferInApp}
                                            options={{
                                                title: "站内转帐",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                cardStyle: {
                                                    backgroundColor: "#ffffff",
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="friendInfo" component={FriendInfo}
                                            options={{
                                                title: "",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                },
                                                cardStyle: {
                                                    backgroundColor: "#ffffff",
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="friendInfoMaterial" component={FriendInfoMaterial}
                                            options={{
                                                title: "",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                cardStyle: {
                                                    backgroundColor: "#ffffff",
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="createGroupChat" component={CreateGroupChat}
                                            options={{
                                                title: "选择联系人",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                cardStyle: {
                                                    backgroundColor: "#ffffff",
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />

                                        <Stack.Screen name="groupList" component={GroupList}
                                            options={{
                                                title: "群聊",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                cardStyle: {
                                                    backgroundColor: "#ffffff",
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="groupMsg" component={GroupMsg}
                                            options={{
                                                title: "",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="groupInfoMaterial" component={GroupInfoMaterial}
                                            options={{
                                                title: "聊天信息",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="setGroupJoin" component={SetGroupJoin}
                                            options={{
                                                title: "设置加群方式",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="groupManage" component={GroupManage}
                                            options={{
                                                title: "群管理",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="sendGroupJoin" component={SendGroupJoin}
                                            options={{
                                                title: "申请加群",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="groupAdmins" component={GroupAdmins}
                                            options={{
                                                title: "群管理",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="groupMembers" component={GroupMembers}
                                            options={{
                                                title: "邀请进群申请",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="groupInfoName" component={GroupInfoName}
                                            options={{
                                                title: "",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#fff',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />








                                        <Stack.Screen name="mineDetailsList" component={MineDetailsList}
                                            options={{
                                                title: "个人信息",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="mineSettings" component={MineSettings}
                                            options={{
                                                title: "设置",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="mineSwitchAccount" component={MineSwitchAccount}
                                            options={{
                                                title: "切换账号",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />
                                        <Stack.Screen name="setAdd" component={SetAdd}
                                            options={{
                                                title: "添加我的方式",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />







                                        <Stack.Screen name="fullVideo" component={FullVideo}
                                            options={{
                                                headerShown: false
                                            }}
                                        />

                                        <Stack.Screen name="notOpen" component={NotOpen}
                                            options={{
                                                title: "",
                                                headerTitleAlign: 'center',
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                                headerShadowVisible: false
                                            }}
                                        />

                                        <Stack.Screen name="logIn" component={LogIn}
                                            options={{
                                                headerShown: false,
                                                headerStyle: {
                                                    backgroundColor: '#EDEDED',
                                                },
                                            }}
                                        />






                                    </Stack.Navigator>
                                </AntDesignProvider>
                            </ConfigProvider>
                        </RootSiblingParent>
                    </NavigationContainer>
                ) : (<CreateWallet />)
            }
        </>
    )
}

const ConnectedApp = connect(mapState)(Pages);

export default class App extends Component {
    render() {
        return (
            <RealmProvider schema={Profile}>
                <Provider store={store}>
                    <ConnectedApp />
                </Provider>
            </RealmProvider>
        )
    }
}



const styles = StyleSheet.create({
    navigatorImage: {
        width: pTx(30),
        height: pTx(20),
        alignSelf: "center"
    },
})